<?php
$this->pageTitle = Yii::app()->name . ' - ' . Yii::t('home', 'foretell');
$this->breadcrumbs = array(
    Yii::t('home', 'foretell')
);

if (Yii::app()->user->isGuest) {
    $baseUrl = Yii::app()->getBaseUrl(true);
    $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
        'id' => 'mydialog',
        // additional javascript options for the dialog plugin
        'options' => array(
            'title' => Yii::t('home', 'message'),
            'autoOpen' => true,
            'modal' => true,
            'beforeClose' => 'js:function(){window.location = "' . $baseUrl . '/index.php?r=site/index";}',
            'buttons' => array(
                Yii::t('home', 'close') => 'js:function(){window.location = "' . $baseUrl . '/index.php?r=site/login";}'
            ),
        ),
    ));

    echo Yii::t('home', 'require_login');

    $this->endWidget('zii.widgets.jui.CJuiDialog');
    return;
}
?>

<h1><?= Yii::t('foretell', 'foretell') ?></h1>

<div class="form">
    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'foretell-form',
        'enableClientValidation' => true,
        'clientOptions' => array(
            'validateOnSubmit' => true,
        ),
    ));
    ?>

    <table>
        <tr>
            <td>
                <?php echo $form->labelEx($model, 'package'); ?>
            </td>
            <td>
                <?php
                $opts = CHtml::listData($package, 'package_id', 'package_name_' . Yii::app()->language);
                echo $form->dropDownList($model, 'package', $opts, array(
                    'ajax' => array(
                        'type' => 'POST', //request type
                        'url' => CController::createUrl('foretellPrice'),
                        'update' => '#price',
                        'data' => array('package_id' => 'js:this.value'),
                        'success' => 'js:function(data){ console.log(data); $("#ForetellForm_price").val(data); }'
                    ))
                );
//                echo $form->dropDownList($model, 'package', $opts, array('empty' => ''));
                ?>
            </td>
            <td>
                <?php echo $form->labelEx($model, 'price'); ?>
            </td>
            <td>
                <?php echo $form->textField($model, 'price', array('placeholder' => $price . ' ' . Yii::t('foretell', 'minimum'), 'value' => $price)); ?>
            </td>
        </tr>
        <tr>
            <td colspan="4"><?php echo $form->error($model, 'package'); ?></td>
        </tr>
        <tr>
            <td colspan="4"><?php echo $form->error($model, 'price'); ?></td>
        </tr>
        <tr>
            <td colspan="4" style="text-align: center;"><?php echo CHtml::submitButton(Yii::t('foretell', 'save')); ?></td>
        </tr>
    </table>

    <?php $this->endWidget(); ?>
</div><!-- form -->

<fieldset style="border: 1px solid #ccc; border-radius: 5px;">
    <legend><h3><?= Yii::t('foretell', 'lists') ?></h3></legend>
    <?php
    $dataProvider = new CActiveDataProvider('Order', array('criteria' => array(
            'condition' => 'cust_id=' . Yii::app()->user->id)));
    $this->widget('zii.widgets.grid.CGridView', array(
        'dataProvider' => $dataProvider,
        'columns' => array(
            'order_id',
            array(
                'name' => 'cust_id',
                'value' => array($this, 'gridCustomerColumn'),
            ),
            array(
                'name' => 'status',
                'value' => array($this, 'gridStatusColumn'),
            ),
            'name',
            'surname',
            array(
                'name' => 'create_date',
                'value' => 'date("j M Y", strtotime($data->create_date))',
            ),
            array(
                'class' => 'CButtonColumn',
            ),
        ),
    ));
    ?>
</fieldset>
<br/>
<fieldset style="border: 1px solid #ccc; border-radius: 5px;">
    <legend><h3><?= Yii::t('foretell', 'old_lists') ?></h3></legend>
    <?php
    $dataProvider = new CActiveDataProvider('Order', array('criteria' => array(
            'condition' => 'cust_id=' . Yii::app()->user->id)));
    $this->widget('zii.widgets.grid.CGridView', array(
        'dataProvider' => $dataProvider,
        'columns' => array(
            'order_id',
            array(
                'name' => 'cust_id',
                'value' => array($this, 'gridCustomerColumn'),
            ),
            array(
                'name' => 'status',
                'value' => array($this, 'gridStatusColumn'),
            ),
            'name',
            'surname',
            array(
                'name' => 'create_date',
                'value' => 'date("j M Y", strtotime($data->create_date))',
            )
        ),
    ));
    ?>
</fieldset>

